@extends('admin.layouts.master')

@section('content')

<div class="row" id="Data-Form" style="display:none;">
	<div class="col-md-12">
		<section class="panel aw-content">
			<header class="panel-heading">{{$nav_name}} - <h5 style="display: inline-block;">@{{data.name}}</h5></header>
			<div class="col-md-12">
			@foreach ($nav as $list)
				@if ($list->id != 1)
				<div class="overflow-hidden aw-checkbox-root Js-label-parents" data-id="{{$list->id}}">
					<div class="aw-checkbox-list-title">
						<a class="Js-label-all" data-id="{{$list->id}}" data-count="{{$list->count}}" href="javascript:;">
                    		{{$list->name}}
                    	</a>
					</div>
					@if ($list->count > 0)
					<div class="aw-checkbox-list Js-label-list" data-id="{{$list->id}}">
						@foreach ($list->nav_li as $li)
							@if ($li->status == 1)
							<a class="Js-label-list-li" data-id="{{$li->id}}" href="javascript:;">
                                {{$li->name}}
                            </a>
							@endif
					    @endforeach
	                </div>
	                @endif
				</div>
				@endif
			@endforeach
				<div class="col-md-12 aw-content-btn">
					<a class="btn btn-gules" href="javascript:;" v-on:click="Save()">保存</a>
					<a class="btn btn-gray" href="/admin/system/class-list-li?page_id=18&id_category=3">取消</a>
				</div>
			</div>
		</section>
	</div>
</div>

@section('pagejs')
@parent

<!--表单验证-->
<script type="text/javascript">
var MJS_URLArry=URLArry;
var Get_form={
	page_id:16
}
$.extend(Get_form,MJS_URLArry)
var ajax_data={
	api:'/adminapi/admin/admin-root-info',
	form_data:Get_form,
	tips:false,
}
var Ajax_Vue_Fun=function(vue_data){
	vm=new Vue({
		el:'#Data-Form',
		data:{
			data:vue_data,
		},
		methods:{
			Save:function(){
				console.log(this.data);
				For_Ids()
				var ajax_data_edit={
					api:'/adminapi/admin/admin-root-save',
					form_data:this.data,
					tips:'编辑职位权限成功',
					//to_url:'/admin/system/class-list-li?page_id=18&id_category=3',
				}
				postData(ajax_data_edit)
			}
		}
	})
	for(i=0;i<vm.data.root.length;i++){
		var Id=vm.data.root[i];
		console.log()
		$('.Js-label-parents[data-id="'+Id+'"]').addClass('active')
		$('.Js-label-list-li[data-id="'+Id+'"]').addClass('active')
	}
	console.log(vm)
	$('#Data-Form').fadeIn(0)
}
getData(ajax_data,Ajax_Vue_Fun)
function For_Ids(){
	var Parents=$('.Js-label-parents')
	var ids=[];
	for(i=0;i<Parents.length;i++){
		var Parents_id=Parents.eq(i).attr('data-id');
		if(Parents.eq(i).hasClass('active')){
			ids.push(Parents_id)
			var List=$('.Js-label-list[data-id="'+Parents_id+'"]').children('a');
			for(ii=0;ii<List.length;ii++){
				var List_id=List.eq(ii).attr('data-id');
				if(List.eq(ii).hasClass('active')){
					ids.push(List_id)
				}
			}
		}
		console.log(ids)
	}
	vm.data.root=ids;
}
$(document).on('click','.Js-label-all',function(){
	var This=$(this)
	var This_Count=This.attr('data-count')
	var This_Id=This.attr('data-id')
	if(!This_Count){
		return;
	}
	var List=$('.Js-label-list[data-id="'+This_Id+'"]')
	var Parents=$('.Js-label-parents[data-id="'+This_Id+'"]')
	if(Parents.hasClass('active')){
		List.children('a').removeClass('active')
		Parents.removeClass('active')
	}else{
		List.children('a').addClass('active')
		Parents.addClass('active')
	}
})

$(document).on('click','.Js-label-list-li',function(){
	var This=$(this)
	var Parents=This.parents('.Js-label-parents');
	var List=Parents.children('.Js-label-list').children('a')
	var ids=[];
	if(This.hasClass('active')){
		This.removeClass('active')
		for(i=0;i<List.length;i++){
			var List_id=List.eq(i).attr('data-id');
			if(List.eq(i).hasClass('active')){
				ids.push(List_id)
			}
			console.log(ids)
		}
		console.log(ids.length)
		if(ids.length<1){
			Parents.removeClass('active')
		}
	}else{
		This.addClass('active')
		Parents.addClass('active')
	}
})
</script>
@endsection

@endsection

